package top.glike.ssl.auto.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.glike.ssl.auto.domain.SslServer;
import top.glike.ssl.auto.service.ISslServerService;
import top.glike.ssl.common.annotation.Log;
import top.glike.ssl.common.core.controller.BaseController;
import top.glike.ssl.common.core.domain.AjaxResult;
import top.glike.ssl.common.core.page.TableDataInfo;
import top.glike.ssl.common.enums.BusinessType;
import top.glike.ssl.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 服务器管理Controller
 *
 * @author Sophia
 * @date 2025-10-12
 */
@RestController
@RequestMapping("/auto/server")
public class SslServerController extends BaseController {

    @Autowired
    private ISslServerService sslServerService;

    /**
     * 查询服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('auto:server:list')")
    @GetMapping("/list")
    public TableDataInfo list(SslServer sslServer) {
        startPage();
        List<SslServer> list = sslServerService.selectSslServerList(sslServer);
        return getDataTable(list);
    }

    /**
     * 导出服务器管理列表
     */
    @PreAuthorize("@ss.hasPermi('auto:server:export')")
    @Log(title = "服务器管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SslServer sslServer) {
        List<SslServer> list = sslServerService.selectSslServerList(sslServer);
        ExcelUtil<SslServer> util = new ExcelUtil<SslServer>(SslServer.class);
        util.exportExcel(response, list, "服务器管理数据");
    }

    /**
     * 获取服务器管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('auto:server:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sslServerService.selectSslServerById(id));
    }

    /**
     * 新增服务器管理
     */
    @PreAuthorize("@ss.hasPermi('auto:server:add')")
    @Log(title = "服务器管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SslServer sslServer) {
        return toAjax(sslServerService.insertSslServer(sslServer));
    }

    /**
     * 修改服务器管理
     */
    @PreAuthorize("@ss.hasPermi('auto:server:edit')")
    @Log(title = "服务器管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SslServer sslServer) {
        return toAjax(sslServerService.updateSslServer(sslServer));
    }

    /**
     * 删除服务器管理
     */
    @PreAuthorize("@ss.hasPermi('auto:server:remove')")
    @Log(title = "服务器管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sslServerService.deleteSslServerByIds(ids));
    }
}
